package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createagentBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.removeagentBean;
import com.ymatou.iapi.godmch.service.createagentCall;
import com.ymatou.iapi.godmch.service.removeagentCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
/**
*移除代理类型
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_removeagentType{
	private static removeagentBean bean;
	private static removeagentCall call;
	public  agent_typeWapper agentTypeWapper=new agent_typeWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("移除代理类型");
	}

	@Before
	public void caseUp() {
		bean=new removeagentBean();
		call=new removeagentCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_removeagentType_001() {
		Logger.start(true,"移除代理类型,验证商户id和代理类型id同时存在-没有代理商使用,代理类型多个");
		try {
			
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
    		//获取代理
    		Map<String,Object> map=new HashMap();
    		map.put("mchId", ccbean.getMchId());
    		List<agent_type> list=agentTypeWapper.selectby(map);
            bean.setMchId(ccbean.getMchId());
            bean.setAgentType(list.get(0).getAgentType());
			call.setData(bean);
			call.callService();	
			Logger.verifyEquals("200", call.getString("status"), "验证status");
			Logger.verifyEquals(true, call.getJsonObject().get("result").getAsJsonObject().get("success").getAsBoolean(), "验证success");
			//验证点
			map.put("agentType", list.get(0).getAgentType());
			agent_type agentType=agentTypeWapper.selectby(map).get(0);
			Logger.verifyEquals(-1, agentType.getState(), "验证数据库agent_type 中的status=-1,表示删除");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_removeagentType_002() {
		Logger.start(true,"移除代理类型,验证商户id和代理类型id同时存在-没有代理商使用,代理类型只有一个,返回错误(代理类型需至少保留一个,当仅剩一个时,无法操作删除)");
		try {
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
    		//获取代理
    		Map<String,Object> map=new HashMap();
    		map.put("mchId", ccbean.getMchId());
    		List<agent_type> list=agentTypeWapper.selectby(map);
            bean.setMchId(ccbean.getMchId());
            bean.setAgentType(list.get(0).getAgentType());
			call.setData(bean);
			call.callService();	
			Logger.verifyEquals("200", call.getString("status"), "验证status");
			Logger.verifyEquals(true, call.getJsonObject().get("result").getAsJsonObject().get("success").getAsBoolean(), "验证success");
			//验证点
			map.put("agentType", list.get(0).getAgentType());
			agent_type agentType=agentTypeWapper.selectby(map).get(0);
			Logger.verifyEquals(-1, agentType.getState(), "验证数据库agent_type 中的status=-1,表示删除");
			bean.setAgentType(list.get(1).getAgentType());
			call.callService();	
			Logger.verifyEquals("5008", call.getString("status"), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_removeagentType_003() {
		Logger.start(true,"移除代理类型,验证商户id和代理类型id同时存在-有代理商使用,返回错误");
		try {
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid=GodmchManageCallService.CreateSellerMch(code);
    		//获取代理
    		Map<String,Object> map=new HashMap();
    		map.put("mchId", ccbean.getMchId());
    		List<agent_type> list=agentTypeWapper.selectby(map);
            bean.setMchId(ccbean.getMchId());
            bean.setAgentType(list.get(0).getAgentType());
			call.setData(bean);
			call.callService();	
			Logger.verifyEquals("5007", call.getString("status"), "验证status");
			//验证点
			map.put("agentType", list.get(0).getAgentType());
			agent_type agentType=agentTypeWapper.selectby(map).get(0);
			Logger.verifyEquals(0, agentType.getState(), "验证数据库agent_type 中的status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_removeagentType_004() {
		Logger.start(true,"移除代理类型,验证商户id存在，代理类型id不存在-返回错误");
		try {
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid=GodmchManageCallService.CreateSellerMch(code);
    		//获取代理
    		Map<String,Object> map=new HashMap();
    		map.put("mchId", ccbean.getMchId());
    		List<agent_type> list=agentTypeWapper.selectby(map);
            bean.setMchId(ccbean.getMchId());
            bean.setAgentType(-1);
			call.setData(bean);
			call.callService();	
			Logger.verifyEquals("5001", call.getString("status"), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_removeagentType_005() {
		Logger.start(true,"移除代理类型,验证商户id不存在，代理类型id存在-返回错误");
		try {
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid=GodmchManageCallService.CreateSellerMch(code);
    		//获取代理
    		Map<String,Object> map=new HashMap();
    		map.put("mchId", ccbean.getMchId());
    		List<agent_type> list=agentTypeWapper.selectby(map);
            bean.setMchId(ccbean.getMchId()+1);
            bean.setAgentType(ccbean.getRoleType());
			call.setData(bean);
			call.callService();	
			Logger.verifyEquals("5001", call.getString("status"), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_removeagentType_006() {
		Logger.start(true,"移除代理类型,验证商户id和代理类型id不匹配");
		try {
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			CreateCodeBean ccbean2 = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid=GodmchManageCallService.CreateSellerMch(code);
    		//获取代理
    		Map<String,Object> map=new HashMap();
    		map.put("mchId", ccbean.getMchId());
    		List<agent_type> list=agentTypeWapper.selectby(map);
            bean.setMchId(ccbean2.getMchId());
            bean.setAgentType(ccbean.getRoleType());
			call.setData(bean);
			call.callService();	
			Logger.verifyEquals("5001", call.getString("status"), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_removeagentType_007() {
		Logger.start(true,"不输入setMchId失败");
		try {
//            bean.setMchId(1);
            bean.setAgentType(1);
			call.setData(bean);
			call.callService();	
			Logger.verifyEquals("4001", call.getString("status"), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_removeagentType_008() {
		Logger.start(true,"不输入setMchId失败");
		try {
            bean.setMchId(1);
//            bean.setAgentType(1);
			call.setData(bean);
			call.callService();	
			Logger.verifyEquals("4001", call.getString("status"), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}